package com.briup.cms.web.controller;

/**
 * @Decription
 * @Author:LiuXN
 * @Date:2021/7/20 11:24
 */
import java.util.HashMap;
import javax.servlet.http.HttpServletResponse;
import com.briup.cms.api.AipImageClient;
import com.briup.cms.api.Aipocr;
//import com.briup.cms.service.ICallLogService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.baidu.aip.ocr.AipOcr;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @program:
 * @description: 智能识别接口
 * @author: Roaming
 * @create: 2021-01-15
 **/
@Api(tags = "文字识别相关接口")
@Validated
@RestController
@RequestMapping("/text")
public class textController {

//    @Autowired
//    private ICallLogService callLogService;
    @ApiOperation(value = "文字识别")
    @PostMapping("text")
    public void image( @RequestParam("file") MultipartFile file,HttpServletResponse resp) throws Exception {
        // 获取图像识别客户端
        AipOcr client = Aipocr.getInstance();
        //调用sdk完成识别功能
        JSONObject res = client.basicAccurateGeneral(file.getBytes(), new HashMap<>());
        // 手动返回json
//		定义相应报文相应头信息
        resp.setHeader("Content-Type", "application/json;charset=UTF-8");
 /*
        将识别的数据写入数据库
        CallLog log=new CallLog();
        log.setCallTime(new Date().getTime());
        log.setComment(res.toString());
        callLogService.save(log);
         */
        //		将识别结果写入到相应体
        resp.getWriter().write(res.toString());

    }
}
